// pages/racquetslist/racquetslist.js
let datas = require('../../data/racquets-data');
Page({
  data: {
    swiperimage: [{
        "id": 1,
        "src": '/images/background/list-1.jpeg'
      },
      {
        "id": 2,
        "src": '/images/background/list-2.jpeg'
      },
      {
        "id": 3,
        "src": '/images/background/list-3.jpeg'
      },
      {
        "id": 4,
        "src": '/images/background/list-4.jpeg'
      },
    ],

    classType: [
      {
        "id": 0,
        "src": '/images/temp/cate1.jpg',
        "type": [{
            "typeid": 11,
            "typename": 'Pro Staff',
          },
          {
            "typeid": 12,
            "typename": 'Clash',
          },
          {
            "typeid": 13,
            "typename": 'Ultra',
          },
          {
            "typeid": 14,
            "typename": 'Blade',
          },
        ]
      },
      {
        "id": 1,
        "src": '/images/temp/cate2.jpg',
        "type": [{
            "typeid": 21,
            "typename": 'Gravity',
          },
          {
            "typeid": 22,
            "typename": 'Instinct',
          },
          {
            "typeid": 23,
            "typename": 'Prestige',
          },
          {
            "typeid": 24,
            "typename": 'Speed',
          },
        ]
      },
      {
        "id": 2,
        "src": '/images/temp/cate3.jpg',
        "type": [{
            "typeid": 31,
            "typename": 'Pure Aero',
          },
          {
            "typeid": 32,
            "typename": 'Pure Drive',
          },
          {
            "typeid": 33,
            "typename": 'Pure Strike',
          },
        ]
      },
      {
        "id": 3,
        "src": '/images/temp/cate4.png',
        "type": [{
            "typeid": 41,
            "typename": 'Ezone',
          },
          {
            "typeid": 42,
            "typename": 'Vcore Pro',
          },
          {
            "typeid": 43,
            "typename": 'Vcore',
          },
        ]
      },
    ], //分类的变量

    subProductList: [], //二级菜单显示的产品
    productList: [], //分类后的产品列表
    productAll: [],
  },


  searchTab(e) {
    let p = this.data.productAll;
    let id = e.currentTarget.id;
    let list = [];
    for (let i = 0; i < p.length; i++) {
      if (p[i].classid - 1 == id) {
        list.push(p[i]);
      }
    }
    this.setData({
      productList: list,
      // subProductList: list,
    })
  },

  searchSubList(e) {
    console.log(e);
    let sp = this.data.productAll;
    let subList = [];
    for (let i = 0; i < sp.length; i++) {
      let str = sp[i].src;
      //let reg = /(?<=racquets\/).+(?=.jpeg)/;
      let reg = new RegExp("(?<=racquets\/).+(?=.jpeg)", 'g');
      let matchResult = str.match(reg);
      if (e.currentTarget.id == matchResult) {
        subList.push(sp[i]);
      }
    }
    this.setData({
      productList: subList,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '浏览'
    })
    this.setData({
      productAll: datas.racquets_data
    })
  },

  toDetail(e) {
    console.log(e);
    let postId = e.currentTarget.dataset.pid;
    console.log(postId);
    wx.navigateTo({
      url: '/pages/detail/detail?postId=' + postId,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})